<template>
  <el-card class="empinfo">
    <el-tabs v-model="activeName">
      <el-tab-pane label="用户管理" name="first">
        <el-form
          :model="ruleForm"
          ref="ruleForm"
          :rules="rules"
          label-width="100px"
          style="width:450px ;margin: 100px auto 100px;"
        >
          <el-form-item label="姓名：" prop="username">
            <el-input
              type="text"
              v-model="ruleForm.username"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码：" prop="password">
            <el-input
              type="password"
              v-model="ruleForm.password"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm">修改</el-button>
            <el-button @click="$router.push('/employees')">取消</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="个人详情" name="second">
        <user-info />
      </el-tab-pane>
      <el-tab-pane label="岗位信息" name="third">
        <job-info />
      </el-tab-pane>
    </el-tabs>
  </el-card>
</template>

<script>
//导入获取员工信息接口，和根据id更新员工数据接口
import { getsUser, getSroleUser } from '@/api/user'
import userInfo from './user-info.vue'
import jobInfo from './job-info.vue'

export default {
  name: 'empinfo',
  components: {
    jobInfo,
    userInfo
  },

  data () {
    return {
      activeName: 'first',
      //员工信息
      ruleForm: {},
      rules: {
        username: [{ required: true, message: '请输入名字', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      }
    }
  },
  created () {
    this.getempList()
  },
  methods: {
    //根据id获取员工信息
    async getempList () {
      let res = await getsUser(this.$route.query.id)
      this.ruleForm = res.data
    },
    submitForm () {
      this.$refs.ruleForm.validate(async v => {
        if (v) {
          await getSroleUser(this.ruleForm)
          this.$message.success('修改成功')
          this.$router.push('/employees')
        }
      })
    }
  }
}
</script>

<style>
.empinfo {
  margin: 20px;
}
</style>
